FROM node:18-alpine AS builder
WORKDIR /app
COPY . .
RUN if [ -f package.json ]; then npm ci && (npm run build:h5 || npm run build || true); fi

FROM node:18-alpine
WORKDIR /app
ENV PORT=80
RUN npm i -g serve
COPY --from=builder /app /app
EXPOSE 80
CMD sh -c 'if [ -d ./dist/build/h5 ]; then DIR=./dist/build/h5; elif [ -d ./dist/h5 ]; then DIR=./dist/h5; elif [ -d ./dist ]; then DIR=./dist; else DIR=.; fi; exec serve -s "$DIR" -l "$PORT"'